package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class UserController {

    @GetMapping("/user")
    public String showAllUser(){
        System.out.println("查询了所有用户信息");
        return "/users.jsp";
    }

    @GetMapping("/user/{id}")
    public String showUserDetail(@PathVariable("id") int userId){
        System.out.println("查询了id"+userId+"的用户");
        return "/userDetail.jsp";
    }

    @PostMapping("/user")
    public String addUser(User user){
        System.out.println("添加了用户信息");
        System.out.println(user);
        return "/index.jsp";
    }

    @DeleteMapping("/user/{id}")
    public String deleteUser(@PathVariable("id") int userId){
        System.out.println("删除了id为"+userId+"的用户");
//        return "/index.jsp";
        return "redirect:/index.jsp";
    }


    @PutMapping("/user/{userId}")
    public String updateUser(User user){
        System.out.println(user+"修改");
//        return "/index.jsp";
        return "redirect:/index.jsp";
    }


}
